<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<!--<input type="button" value="入栈" id="btn1" />
		<input type="button" value="出栈" id="btn2" />-->
		<input type="button" value="输入数字" id="btn1" />
		<input type="button" value="计算平均值" id="btn2" />
		<p id="num"></p>
		<p id="avg"></p>
		<script type="text/javascript">
			var a = [];
			var push = document.getElementById("btn1");
			var pop = document.getElementById("btn2");
			push.onclick = function(e) {
				var p = document.getElementById("num");
				var r = parseInt(Math.random() * 1000);
				a.push(r);
				var span = document.createElement("span");
				span.innerText = r;
				span.style.marginLeft = "20px";
				p.appendChild(span);
				/*console.log(stack.toString());*/
			}
			btn2.onclick=function(){
				var s=0;
				for(var i in a){
					s=s+a[i];
				}
				document.getElementById("avg").innerText="平均值为："+(s/a.length)
			}
			/*pop.onclick = function(e) {
				var v = stack.pop();
				alert(v + "出栈");
				console.log(stack.toString());
			}*/
		</script>
	</body>

</html>